import router from './autoRouter';
import store from '@/store'; // 验权
import { WHITE_LIST } from '@/constants/index';

import { Toast } from 'vant';
import NProgress from 'nprogress';

router.beforeEach((to, from, next) => {
    NProgress.start();
    Toast.clear();
    // || to.path=='/a'
    if (store.getters.isAuthed && WHITE_LIST.indexOf(to.path) == -1 ) {
        if (to.path === '/login') {
            next({ path: '/orderlist' });
            NProgress.done();
        } else {
            next();
        }
    } else {
        // || to.path=='/a'
        if (WHITE_LIST.indexOf(to.path) !== -1 ) {
            next();
        } else {
            next('/login');
            NProgress.done();
        }
        return;
    }
    return;
});

router.afterEach(() => {
    NProgress.done();
});
